package com.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/demo03.do")
public class Demo03Servlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        ///demo20211015/demo03.do
        //获取请求的URI 资源路径
        System.out.println(req.getRequestURI());
        //http://localhost:8083/demo20211015/demo03.do
        //获取请求的URL 资源全路径
        System.out.println(req.getRequestURL());
        //0:0:0:0:0:0:0:1
        //获取客户端的IP地址
        System.out.println(req.getRemoteHost());
        //zh-CN,zh;q=0.9
        //获取请求头信息
        System.out.println(req.getHeader("Accept-Language"));
        System.out.println(req.getHeader("Cookie"));
        System.out.println(req.getHeader("User-Agent"));
        //GET
        //获取请求方式
        System.out.println(req.getMethod());
        //请求转发的写法
        req.getRequestDispatcher("/demo04.do").forward(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //无论get方式还是post方式 都执行同一段逻辑
        doGet(req, resp);
    }
}
